<html>
<head><meta charset="utf-8"><title>Can other backends handle freeze? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html">Can other backends handle freeze?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244780260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Can%20other%20backends%20handle%20freeze%3F/near/244780260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html#244780260">(Jul 03 2021 at 04:45)</a>:</h4>
<p>I was contemplating adding <a href="https://llvm.org/docs/LangRef.html#freeze-instruction">LLVM's <code>freeze</code></a> as an intrinsic, to allow experimenting with using it for fast-math in nightly.  (It would be interesting for <a href="https://llvm.org/docs/LangRef.html#fast-math-flags"><code>nnan</code>/<code>ninf</code>/<code>fast</code></a>, as those return <code>poison</code> for bad input -- they're not immediate UB.  So one way to expose them to safe code -- as needed for operators -- would be to have a safe way to decay that poison down to just an unknown-but-initialized value, which freeze can do.)</p>
<p>But I wanted to check how that would impact other backends.</p>
<p>As far as I could tell, cranelift doesn't have uninitialized or poison because it doesn't have UB.  So freeze would be a nop there, which would be fine.  (Right?)</p>
<p>I know nothing about GCC's IR, though.  Does it have a similar idea to freeze?</p>



<a name="244782076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Can%20other%20backends%20handle%20freeze%3F/near/244782076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html#244782076">(Jul 03 2021 at 05:33)</a>:</h4>
<p>wouldn't you want to expose only intrinsics which implicitly use <code>freeze</code> themselves?</p>



<a name="244782127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Can%20other%20backends%20handle%20freeze%3F/near/244782127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html#244782127">(Jul 03 2021 at 05:34)</a>:</h4>
<p>so they could just default to non-fast-math if they can't do the <code>freeze(... nnan/ninf/fast)</code> combo</p>



<a name="244783674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Can%20other%20backends%20handle%20freeze%3F/near/244783674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html#244783674">(Jul 03 2021 at 06:10)</a>:</h4>
<p>I was thinking of separate intrinsics to avoid extra <code>freeze</code>s.</p>
<p>For example, <code>fast_fadd</code> could be <code>MaybeUninit&lt;f32&gt; + MaybeUninit&lt;f32&gt; -&gt; MaybeUninit&lt;f32&gt;</code>, called in <code>impl Add for FastF32</code>, and only <code>freeze</code> on <code>impl From&lt;FastF32&gt; for f32</code>.</p>
<p>(And in general it'd be nice to offer freeze on <code>MaybeUninit</code>.)</p>
<p>But I guess it could be a specific <code>fastmath_freeze</code> so that it being a nop when <code>fast_fadd</code> is just normal add would also be obviously fine.</p>



<a name="244880292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Can%20other%20backends%20handle%20freeze%3F/near/244880292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html#244880292">(Jul 04 2021 at 22:17)</a>:</h4>
<p>We already have problems with codegen backends not sharing LLVM's model so closely and <code>cg_ssa</code> embedding a lot of LLVM-internal logic, per <a href="#narrow/stream/131828-t-compiler/topic/Considering.20a.20future.20integration.20of.20the.20gcc.20backend">https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Considering.20a.20future.20integration.20of.20the.20gcc.20backend</a></p>



<a name="244880931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Can%20other%20backends%20handle%20freeze%3F/near/244880931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html#244880931">(Jul 04 2021 at 22:36)</a>:</h4>
<p>The paper that introduces the concept of the freeze operator asserts that all IRs they looked at feature UB: <a href="https://www.cs.utah.edu/~regehr/papers/undef-pldi17.pdf">https://www.cs.utah.edu/~regehr/papers/undef-pldi17.pdf</a></p>
<p>The typical pipeline is ${LANG} -&gt; Generic-&gt; Gimple -&gt; RTL -&gt; asm,<br>
and I am seeing nothing akin to <code>freeze</code> while paging through <a href="https://gcc.gnu.org/onlinedocs/gccint/">https://gcc.gnu.org/onlinedocs/gccint/</a> but it is surely incomplete.</p>



<a name="244881566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Can%20other%20backends%20handle%20freeze%3F/near/244881566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Can.20other.20backends.20handle.20freeze.3F.html#244881566">(Jul 04 2021 at 22:57)</a>:</h4>
<p>You might ask David Malcom, who works on GCC.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>